﻿@{
    Layout = "~/Views/Shared/_TestLayout.cshtml";
}
@section headSec{
    <script src="/Content/uploadify/swfobject.js" type="text/javascript"></script>
    <script src="/Content/uploadify/jquery.uploadify.v2.1.4.min.js" type="text/javascript"></script>
    <link href="/Content/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .textstyle1 {
            color: Red;
            font-weight: bold;
        }

        .textstyle2 {
            color: Green;
            font-weight: bold;
        }
    </style>

    <script type="text/javascript">
        $(document).ready(function() {
            //上传
            $('#fileInput1').uploadify({
                'uploader': '/Content/uploadify/uploadify.swf',
                'script': '/TestMaterial/Add',
                'folder': '/UploadFiles',
                'cancelImg': '/Content/uploadify/cancel.png',
                'fileExt': '*.doc',
                'fileDesc': 'word文档',
                'sizeLimit': 1024 * 1024 * 40, //4M
                'auto': false, //设置为true当选择文件后就直接上传了，为false需要点击上传按钮才上传
                'multi': true,
                'onComplete': onCom,
                'onError': onErr,
                'onAllComplete': onAllComp,
                'scriptData': { '__RequestVerificationToken':  $('@Html.AntiForgeryToken()').val() }
            });
        });
        var res = "";
        function onCom(event, queueID, fileObj, response, data) {
         var resp =eval("("+response+")");
            if (resp.result.errcode != 0) {
                res += "<span class='textstyle1'>" + fileObj.name + " 上传失败 " + resp.result.errmsg + "</span><br>";
            }
            else {
                res += "<span class='textstyle2'>" + fileObj.name + " 上传成功</span><br>";
            }
        }

        function onErr(event, queueId, fileObj, errorObj) {
            alert(fileObj.name);
        }

        function onAllComp() {
            alert(res);
            $("#result").empty();
            $("#result").html(res);
            res = "";
        }
    </script>
}

<div>
    <p><input id="fileInput1" name="fileInput1" type="file" /></p>
    <p style="margin-top:5px;font-size:14px;font-weight:bold;">
        <a href="javascript:$('#fileInput1').uploadifyUpload();">上传文件</a>
    </p>
    <p style="margin-top:5px;font-size:14px;font-weight:bold;" id="result"></p>
</div>
